package com.zyz.forum_test.util;

import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

public class WebDriverUtil {

    private static WebDriver driver;
    /**
     * WebDriverInit初始化webDriver
     * @return
     */
    public static WebDriver getDriver() {
        // 单例
        if (driver != null) return driver;
        WebDriverManager.chromedriver().setup();
        ChromeOptions chromeOptions = new ChromeOptions();
        chromeOptions.addArguments("--remote-allow-origins=*"); // 允许所有网段
        driver = new ChromeDriver(chromeOptions);
        // 调整窗口大小为最大化
        driver.manage().window().maximize();
        return driver;
    }

    /**
     * 关闭driver
     */
    public static void quit() {
        if (driver != null) driver.quit();
    }
}
